package com.jiang.text;

import redis.clients.jedis.Jedis;

public class Shop {

    private static int count=1;

    public  void buy() {
        synchronized (this.getClass()) {
            if (count > 0) {
                count--;
                System.out.println(Thread.currentThread().getName() + ":购买成功");
            } else {
                System.out.println(Thread.currentThread().getName() + ":库存不足");
            }
        }
    }
    public void buyone(){
        if(Redislock.getlock("buyone")){
            if (count > 0) {
                count--;
                System.out.println(Thread.currentThread().getName() + ":购买成功");
            } else {
                System.out.println(Thread.currentThread().getName() + ":库存不足");
            }
        }
        Redislock.kaisuo("buyone");
    }
}
